package api

import (
	"cttu/common"
	"cttu/models/db"
	"cttu/models/structs"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

// DefaultIntervalInMilliSeconds 数值常量
const (
	DefaultIntervalInMilliSeconds = 1000
)

func IndexApi(c *gin.Context) {
	c.String(http.StatusOK, "It works")
}

func Corntab(c *gin.Context){
	// 创建定时器，执行计划任务
	common.CreateTicker(DefaultIntervalInMilliSeconds, common.DoCrontab)

}

func User(c *gin.Context) {


	// 增
	//user1 := structs.User{Name: "张三", Age: 12, Height: 186, Weight: 56, Hobby: "足球", Phone: "15733112942"}
	//user2 := structs.User{Name: "李四", Age: 16, Height: 186, Weight: 56, Hobby: "冰球", Phone: "15733112942"}
	//user3 := structs.User{Name: "王五", Age: 18, Height: 186, Weight: 56, Hobby: "篮球", Phone: "15733112942"}

	//db.DB.Create(&user1)
	//db.DB.Create(&user2)
	//db.DB.Create(&user3)

	// 查询所有的记录
	var users []structs.User
	db.DB.Find(&users)
	// SELECT * FROM users;

	msg := fmt.Sprintf("success")
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg": msg,
		"data": users,
	})

}
